package com.tao.Change;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Change {
    public static void main(String[] args) {
        boolean loop = true;
        Scanner Scanner = new Scanner(System.in);
        String key = "";

        //完成零钱通明细
        String one ="----------零钱通明细----------";

        //完成收益入账
        double money = 0;
        Date date = null;
        double balance = 0;
        SimpleDateFormat sdf = null;//用于日期格式化

        //完成消费
        String note = " ";

        do{
            System.out.println("\n==========零钱通菜单==========");
            System.out.println("\t\t1 零钱通明细");
            System.out.println("\t\t2 收益入账");
            System.out.println("\t\t3 消费");
            System.out.println("\t\t4 退出");

            System.out.println("请选择（1-4）");
            key =Scanner.next();
            switch(key){
                case "1":
                    System.out.println(one);
                    break;
                case "2":
                    System.out.println("入账金额:");
                    money =Scanner.nextDouble();
                    if(money<=0){
                        System.out.println("入账金额需要大于0");
                        break;
                    }
                    balance += money;
                    date = new Date();
                    sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm");
                    one +="\n收益入账\t+" + money + "\t" +sdf.format(date) + "\t" + "余额：" + balance;
                    break;
                case "3":
                    System.out.println("消费金额：");
                    money =Scanner.nextDouble();
                    if(money<=0||money>balance){
                        System.out.println("余额不足");
                        System.out.println("您的余额还有：" + balance);
                        break;
                    }
                    System.out.println("花费说明");
                    note = Scanner.next();
                    balance -= money;
                    one +="\n" + note + "\t-" + money + "\t" +sdf.format(date) + "\t" + "余额：" + balance;
                    break;
                case "4":
                    //让用户判断是否真的要退出
                    String choice = " ";
                    while(true){
                        System.out.println("你确定要退出吗？y/n");
                        choice = Scanner.next();
                        if("y".equals(choice)||"n".equals(choice)){
                            break;
                        }
                    }
                    if("y".equals(choice)){
                        loop = false;
                    }
                    break;
                default:
                    System.out.println("输入有误");
            }
        }while(loop);
    }
}
